package com.bdqn.web.contoller;

import bean.Lobby;
import bean.PlatformMember;
import com.bdqn.dao.platform.PlatformDao;
import com.bdqn.dao.vo.ResultVo;
import com.bdqn.web.BaseAppController;
import com.bdqn.service.LobbyService;
import com.bdqn.service.platform.Shuangzuan;
import com.bdqn.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/app/platform")
public class Platformcontoller extends BaseAppController {
    @Autowired
    private LobbyService lobbyService;
    @Autowired
    PlatformDao platformDao;
    @Autowired
    Shuangzuan shuangzuan;

    @CrossOrigin(origins = "*",maxAge = 3600)
    @RequestMapping("/list")
    public List<Lobby> getLobbyAll(){
        //System.out.println(111);
        System.out.println(lobbyService.findAll());
        return lobbyService.findAll();
    }

    @CrossOrigin(origins = "*",maxAge = 3600)
    @RequestMapping("/LobbyName")
    public List<Lobby> getLobbyName(@RequestParam("select") String select){
        List<Lobby> name = lobbyService.findName(select);
        return name;
    }

    @CrossOrigin(origins = "*",maxAge = 3600)
    @RequestMapping("/pull/buyer")
    public ResultVo pullBuyer(@ModelAttribute PlatformMember platformMember){
        //判断是否存在此平台
        //获取官网地址
        Lobby platform  = lobbyService.findId(platformMember.getId());
        System.out.println(platform);
        if(null==platform){

            return renderRb("获取买号失败");
        }
//        获取官网地址
        platformMember.setUrl(platform.getWebsite());
//        if(platform.getNamePinyin().equals("shaungzuan")) {
            shuangzuan = new Shuangzuan();
            Map<String, List<Object>> result  = shuangzuan.process(platformMember);
//        }
        if(null == result || result.size()<=0){
            return renderError("网络超时请稍后再试");
        }
        for (Map.Entry<String,List<Object>> str: result.entrySet()) {
            if(str.getValue()==null || str.getValue().size()<=0){
                return renderError(str.getKey());
            }else{
                return renderRb(str.getValue());
            }
        }
        return renderError("网络超时请稍后再试");
    }
}
